package com.ruoyi.binance.controller;

import java.math.BigDecimal;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.binance.service.IBinanceDailyMarketService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.binance.domain.BinanceAutoSingleCell;
import com.ruoyi.binance.service.IBinanceAutoSingleCellService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 自动单格Controller
 * 
 * @author zq
 * @date 2025-09-10
 */
@RestController
@RequestMapping("/binance/autoCell")
public class BinanceAutoSingleCellController extends BaseController
{
    @Autowired
    private IBinanceAutoSingleCellService binanceAutoSingleCellService;
    @Autowired
    private IBinanceDailyMarketService binanceDailyMarketService;

    /**
     * 查询自动单格列表
     */
    @PreAuthorize("@ss.hasPermi('binance:autoCell:list')")
    @GetMapping("/list")
    public TableDataInfo list(BinanceAutoSingleCell binanceAutoSingleCell)
    {
        startPage();
        List<BinanceAutoSingleCell> list = binanceAutoSingleCellService.selectBinanceAutoSingleCellList(binanceAutoSingleCell);
        return getDataTable(list);
    }

    /**
     * 导出自动单格列表
     */
    @PreAuthorize("@ss.hasPermi('binance:autoCell:export')")
    @Log(title = "自动单格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BinanceAutoSingleCell binanceAutoSingleCell)
    {
        List<BinanceAutoSingleCell> list = binanceAutoSingleCellService.selectBinanceAutoSingleCellList(binanceAutoSingleCell);
        ExcelUtil<BinanceAutoSingleCell> util = new ExcelUtil<BinanceAutoSingleCell>(BinanceAutoSingleCell.class);
        util.exportExcel(response, list, "自动单格数据");
    }

    /**
     * 获取自动单格详细信息
     */
    @PreAuthorize("@ss.hasPermi('binance:autoCell:query')")
    @GetMapping(value = "/{code}")
    public AjaxResult getInfo(@PathVariable("code") String code)
    {
        return success(binanceAutoSingleCellService.selectBinanceAutoSingleCellByCode(code));
    }

    /**
     * 新增自动单格
     */
    @PreAuthorize("@ss.hasPermi('binance:autoCell:add')")
    @Log(title = "自动单格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BinanceAutoSingleCell binanceAutoSingleCell)
    {
        binanceAutoSingleCell.setBuyPric(new BigDecimal("1000000.0"));
        binanceAutoSingleCell.setSellPric(new BigDecimal("1000000.0"));
        int i = binanceAutoSingleCellService.insertBinanceAutoSingleCell(binanceAutoSingleCell);
        if (i > 0) {
            binanceDailyMarketService.autoHighAndLowRange(binanceAutoSingleCell);
        }
        return toAjax(i);
    }

    /**
     * 修改自动单格
     */
    @PreAuthorize("@ss.hasPermi('binance:autoCell:edit')")
    @Log(title = "自动单格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BinanceAutoSingleCell binanceAutoSingleCell)
    {
        return toAjax(binanceAutoSingleCellService.updateBinanceAutoSingleCell(binanceAutoSingleCell));
    }

    /**
     * 删除自动单格
     */
    @PreAuthorize("@ss.hasPermi('binance:autoCell:remove')")
    @Log(title = "自动单格", businessType = BusinessType.DELETE)
	@DeleteMapping("/{codes}")
    public AjaxResult remove(@PathVariable String[] codes)
    {
        return toAjax(binanceAutoSingleCellService.deleteBinanceAutoSingleCellByCodes(codes));
    }
}
